#pragma once

class CValueItem {
public:
  CValueItem(const tstring& name, const tstring& cmdName, const tstring& targetValue,
    const tstring& upperTolerance, const tstring& lowerTolerance, const tstring& measureUnit)
  : name_(name)
  , cmd_name_(cmdName)
  , target_value_(targetValue)
  , upper_tolerance_(upperTolerance)
  , lower_tolerance_(lowerTolerance)
  , measure_value_(_T("N/A"))
  , measure_unit_(measureUnit)
  {
    ok_ = false;
  }

  ~CValueItem() {}

  bool ok(void) const { return ok_; }
  void set_ok(bool val) { ok_ = val; }

  const tstring& Name(void) const { return name_; }
  void set_name(const tstring& val) { name_ = val; }

  const tstring& cmd_name(void) const { return cmd_name_; }
  void set_cmd_name(const tstring& val) { cmd_name_ = val; }

  const tstring& target_value(void) const { return target_value_; }
  void set_target_value(const tstring& val) { target_value_ = val; }

  const tstring& upper_tolerance(void) const { return upper_tolerance_; }
  void set_upper_tolerance(const tstring& val) { upper_tolerance_ = val; }

  const tstring& lower_tolerance(void) const { return lower_tolerance_; }
  void set_lower_tolerance(const tstring& val) { lower_tolerance_ = val; }

  const tstring& measure_value(void) const { return measure_value_; }
  void set_measure_value(const tstring& val) { measure_value_ = val; }

  const tstring& measure_unit(void) const { return measure_unit_; }
  void set_measure_unit(const tstring& val) { measure_unit_ = val; }

private:
  bool ok_;
  tstring name_;
  tstring cmd_name_;
  tstring target_value_;
  tstring upper_tolerance_;
  tstring lower_tolerance_;
  tstring measure_value_;
  tstring measure_unit_;
};

// CGroupListBox

class CGroupListBox : public CListBox
{
	DECLARE_DYNAMIC(CGroupListBox)

private:
  CBrush background_brush_;
  CBrush selected_brush_;
  CFont small_font_;
  CFont medium_font_;
  CFont large_font_;
  CFont super_font_;
  int small_font_base_size_;
  int medium_font_base_size_;
  int large_font_base_size_;
  int super_font_base_size_;
  int small_font_relative_size_;
  int medium_font_relative_size_;
  int large_font_relative_size_;
  int super_font_relative_size_;
  int internal_margin_;
  int external_margin_;
  int left_margin_;
  int headerHeight;
  int valueHeight;
  int useHeight;
  int indicatorHeight;
  int indicatorWidth;

  std::vector<CValueItem> value_items_;

public:
	CGroupListBox();
	virtual ~CGroupListBox();

public:
  int AddValueItem(const CValueItem& valueItem);
  int DeleteValueItem(int index);
  int InsertValueItem(int index, const CValueItem& valueItem);
  int FindValueItem(const tstring& name, const tstring& cmd) const;
  int SetValueItem(int index, const tstring& value, bool ok);
  int SetItemName(int index, const tstring& newName);
  void Reset(void);
  BOOL AllOk(void) const;
  CValueItem& ValueItem(int index) { return value_items_[index]; }
  const CValueItem& ValueItem(int index) const { return value_items_[index]; }

private:
  int AddString(LPCTSTR);
  int DeleteString(UINT);
  int InsertString(int, LPCTSTR);

protected:
	DECLARE_MESSAGE_MAP()
  virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
public:
  virtual void MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/);
  virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
  virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
  afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
  virtual void PreSubclassWindow();
  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};


